package com.frankie.weibo.miweibo.api.dao.impl;

import com.frankie.weibo.miweibo.api.NewCallback;
import com.frankie.weibo.miweibo.api.WeiboHttpUtil;
import com.frankie.weibo.miweibo.api.dao.IStatusDao;
import com.frankie.weibo.miweibo.api.interf.IMiCallback;
import com.frankie.weibo.miweibo.bean.StatusBean;
import com.frankie.weibo.util.JsonUtil;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Frankie on 2016/8/16.
 */

public class StatusDaoImpl implements IStatusDao {

    @Override
    public void getStatuses(int pageNum, final IMiCallback<List<StatusBean>> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("page", pageNum+"");
        WeiboHttpUtil.get("statuses/home_timeline.json", params, new NewCallback<>(callBack, new NewCallback.Decorator<List<StatusBean>>() {
            @Override
            public List<StatusBean> decorate(JSONObject resultJson) {
                return JsonUtil.handleResponseList(resultJson.optString("statuses"), StatusBean.class);
            }
        }));
    }

}
